/*
 * =====================================================================================
 *
 *       Filename:  valueRange.hpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2009-2-20 14:19:22
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Fang Dongheng (fndisme), fndisme@163.com
 *        Company:  Artcoding, Shanghai, China
 *
 * =====================================================================================
 */
#ifndef FND_GAME_VALUE_RANGE_H__
#define FND_GAME_VALUE_RANGE_H__

#include <utility>
#include <cassert>
#include <iostream>

template<typename T>
class value_range {
public:
    typedef T value_type ;
    typedef value_range<T> class_type ;
    typedef class_type& reference ;
    typedef const class_type& const_reference ;
public:

    const_reference operator=(const_reference v) {
        if(this == &v)
            return *this ;
        Value[0] = v.Value[0] ;
        Value[1] = v.Value[1] ;
        Value[2] = v.Value[2] ;
        return *this ;
      
    }
    value_range(const class_type& v){
        Value[0] = v.Value[0] ;
        Value[1] = v.Value[1];
        Value[2] = v.Value[2] ;}
    value_range(const T& l, const T& m, const T& h){
        Value[0] = l ;
        Value[1] = m ;
        Value[2] = h ;
    }
    value_range() {
        Value[0] = Value[1] = Value[2] = T() ;
    }
public:
    void swap(class_type& v){
        std::swap(Value[0], v.Value[0]);
        std::swap(Value[1], v.Value[1]) ;
        std::swap(Value[2], v.Value[2]) ;
    }
    void print(std::ostream& os)const {
        os <<'(' << Value[0]<< ',' << Value[1] << ',' << Value[2]<< ')' ;
    }
    void getin(std::istream& in) {
        char notuse ;
        in >>std::skipws >> notuse ;
        in >> Value[0];
        in >> notuse ;
        in >> Value[1] ;
        in >> notuse ;
        in >> Value[2];
        in >> notuse ;
    }

    T& operator[](size_t id) {
        return Value[id] ;
    }

    const T& operator[](size_t id) const {
        return Value[id] ;
    }

public:
    T Value[3] ;
    
} ;

template<typename T>
bool operator == (const value_range<T>& lhs,
                  const value_range<T>& rhs) {
    return lhs[0] == rhs[0] &&
        lhs[1] == lhs[1] &&
        lhs[2] == lhs[2] ;
}

    template<typename T>
    std::ostream& operator<<(std::ostream& os, const value_range<T>& r) {
        r.print(os) ;
        return os ;
    }

    template<typename T>
    std::istream& operator>>(std::istream& in, value_range<T>& r) {
        r.getin(in) ;
        return in ;
    }

    typedef value_range<double> normal_number_range ;
#endif

